package com.hf.eagle.web.struts;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.DynaBean;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.hf.eagle.domain.RecruitmentInfo;
import com.hf.eagle.web.base.BaseAction;

/**
 * 人才招聘
 * @author xiaokeheng
 *
 */
public class PersonnelRecruitmentAction extends BaseAction {

	public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		return this.view(mapping, form, request, response);
	}

	/**
	 * 显示人才招聘
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward view(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		DynaBean lazyForm = (DynaBean) form;
		String id = (String) lazyForm.get("id");
		RecruitmentInfo recruitmentInfo = new RecruitmentInfo();
		recruitmentInfo.setId(Long.valueOf(id));
		recruitmentInfo=super.getFacade().getRecruitmentInfoService().getRecruitmentInfo(recruitmentInfo);
		StringBuffer sf = new StringBuffer("<div class=\"pd_title\"><span id=\"hr_title\">"+recruitmentInfo.getJob()+"</span></div>");
		String info=recruitmentInfo.getJob_required();
		if(info!=null) info=info.replaceAll("\r\n", "<br>");
		sf.append("<div class=\"pd\" style=\"margin-left: 20px\"><div id=\"content\">"+info+"</div></div>");
		super.renderText(response, sf.toString());
		return null;
	}
	
	/**
	 * 显示人才招聘列表
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward list(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		DynaBean lazyForm = (DynaBean) form;
		String mod_id = (String) lazyForm.get("mod_id");
        request.setAttribute("mod_id", mod_id);
		RecruitmentInfo recruitmentInfo = new RecruitmentInfo();
		List<RecruitmentInfo> list = super.getFacade().getRecruitmentInfoService().getRecruitmentInfoList(recruitmentInfo);
		request.setAttribute("list", list);
        return mapping.findForward("list");
	}

}